import java.util.Random;

public class Chest extends Block{
	private int chestNumber;
	private boolean isKeyUsed = false;
	private int chestMoney;

	public Chest(String name, int location){
		super(name, location);
	}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//GETTERS AND SETTERS//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	private void setChestMoney(int chestMoney) {
		this.chestMoney = chestMoney;
	}

	@SuppressWarnings("unused")
	private int getChestMoney() {
		return chestMoney;
	}

	public void setKeyUsed(boolean isUsed) {
		this.isKeyUsed = isUsed;
	}

	public boolean isKeyUsed() {
		return isKeyUsed;
	}
	
	public void setChestNumber(int chestNumber) {
	this.chestNumber = chestNumber;
	}

	public int getChestNumber() {
	return chestNumber;
	}
	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//FUNCTIONS//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	public int shuffleChestCards(){ //returns a random number
		Random random = new Random();
		chestNumber=random.nextInt(16)+1;
		return chestNumber;
	}
	
	public void getChestAction(Player[] orderedPlayer, int numberOfPlayers, int numberOfAlivePlayers, int counter, int chestNum){	//a switch function that would get 
		switch(chestNum){ //the random number that you drew then enters it in a switch, each switch has a corresponding function and parameter
			case 1:
				setChestMoney(1000000);
				changeMoney(orderedPlayer, counter, chestMoney);
				break;
			case 2:
				setChestMoney(100000);
				changeMoney(orderedPlayer, counter, chestMoney);
				break;
			case 3:
				setChestMoney(1000000);
				changeMoney(orderedPlayer, counter, chestMoney);
				break;
			case 4:
				setChestMoney(200000);
				changeMoney(orderedPlayer, counter, chestMoney);
				break;
			case 5:
				chest5(orderedPlayer, counter, numberOfPlayers);
				break;
			case 6:
				chest6(orderedPlayer, counter, numberOfPlayers, numberOfAlivePlayers);
				break;
			case 7:
				setChestMoney(-1500000);
				changeMoney(orderedPlayer, counter, chestMoney);
				break;
			case 8:
				setChestMoney(450000);
				changeMoney(orderedPlayer, counter, chestMoney);
				break;
			case 9:
				setChestMoney(-500000);
				changeMoney(orderedPlayer, counter, chestMoney);
				break;
			case 10:
				setChestMoney(-1000000);
				changeMoney(orderedPlayer, counter, chestMoney);
				break;
			case 11:
				setChestMoney(250000);
				changeMoney(orderedPlayer, counter, chestMoney);
				break;
			case 12:
				setChestMoney(2000000);
				changeMoney(orderedPlayer, counter, chestMoney);
				break;
			case 13:
				chest13(orderedPlayer, counter);
				break;
			case 14:
				chest14(orderedPlayer, counter);
				break;
			case 15:
				chest15(orderedPlayer, counter);
				break;
			case 16:
				setChestMoney(1000000);
				changeMoney(orderedPlayer, counter, chestMoney);
				break;
		}		
	}
	
	public void changeMoney(Player[] orderedPlayer, int counter, int chestMoney){	//a function that will handle all the changes in
		orderedPlayer[counter].setMoney((orderedPlayer[counter].getMoney())+(chestMoney));	//money
	}
	
	public void chest5(Player[] orderedPlayer, int counter, int numberOfPlayers){
		orderedPlayer[counter].setMoney(orderedPlayer[counter].getMoney()-(400000*orderedPlayer[counter].getNumberOfHouses()));
		orderedPlayer[counter].setMoney(orderedPlayer[counter].getMoney()-(1150000*orderedPlayer[counter].getNumberOfHotels()));
	}
	
	public void chest6(Player[] orderedPlayer, int counter, int numberOfPlayers, int numberOfAlivePlayers){
		for(int p=0;p<numberOfPlayers;p++){
			if(orderedPlayer[p].isAlive())
			orderedPlayer[p].setMoney(orderedPlayer[p].getMoney()-500000);
		}
		orderedPlayer[counter].setMoney(orderedPlayer[counter].getMoney()+(500000*numberOfAlivePlayers));
	}
	
	public void chest13(Player[] orderedPlayer, int counter){
		if(orderedPlayer[counter].getPosition()==2)
			orderedPlayer[counter].setTotalSteps(38);
		if(orderedPlayer[counter].getPosition()==17)
			orderedPlayer[counter].setTotalSteps(23);
		if(orderedPlayer[counter].getPosition()==33)
			orderedPlayer[counter].setTotalSteps(7);
	}
	public void chest14(Player[] orderedPlayer, int counter){
		orderedPlayer[counter].setHasChestKey(true);
	}
	public void chest15(Player[] orderedPlayer, int counter){
		orderedPlayer[counter].setJailed(true);
	}
}